package com.qingfeng.qfcms.controller.Admin.organization;

import com.qingfeng.qfcms.domin.Organization;
import com.qingfeng.qfcms.page.Page;
import com.qingfeng.qfcms.service.OrganizationService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * ============================================================
 * 版权 ：青峰软件有限公司  版权所有 (c) 2016
 * 作者:  menxd
 * 版本 ：1.0
 * 创建日期 ： 2016/7/29
 * 描述 ：
 * <p>
 * 修订历史 ：
 * ============================================================
 */
@Controller
@RequestMapping("/org")
public class OrganizationController {



    @Resource
    private OrganizationService organizationService;
    @RequestMapping("/OrgList.shtml")
    public String toOrgList(Model model, Page page){

       List<Organization> organizations=organizationService.findPage(page);
        model.addAttribute("organizations",organizations);
        model.addAttribute("page",page.getPageStr("/org/OrgList.shtml"));
        return "/admin/frame/organization/org_list";

    }

    @RequestMapping("deleteORG.shtml")
    public boolean deleteORG(String id){
        try {
            organizationService.deleteById(id);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @RequestMapping("toAddORG.shtml")
    public String toAddORG(){
        return "/admin/frame/organization/org_add";
    }

    @RequestMapping("toEditORG.shtml")
    public String toEditORG(String id,Model model){
        Organization organization=organizationService.get(id);
        model.addAttribute("organization",organization);
        return "/admin/frame/organization/org_edit";
    }
}
